//基地址
let baseUrl="http://101.42.158.48:3000"
// let baseUrl = "http://localhost:3000"


export default (url, data, method = "GET") => {
	if (url == '/mzh/logins') {
		return new Promise((resolve, reject) => {
			uni.request({
				url: baseUrl + url,
				data,
				method,
				success: (res) => {
					resolve(res)
				},
				fail: (err) => {
					reject(err)
				}
			});
		})
	} else {
		let token = uni.getStorageSync('token')
		const headers = {
		 'Content-Type': 'application/json',
		 'Authorization': `Bearer ${token}`, 
		};
		return new Promise((resolve, reject) => {
			uni.request({
				url: baseUrl + url,
				data,
				method,
				header: headers,
				success: (res) => {
					resolve(res);
				},
				fail: (err) => {
					uni.redirectTo({url:'/pages/login/login'})
					reject(err);
				}
			});
		});
	}

}

/*
组件内使用：
1：引入当前文件
	import request from '当前文件路径'
	
2：请求接口数据
例如：
async function getlist(){
	const data=await request('/zsl/getlist',{data:'要传递的数据 --可选参数'},'POST')
	console.log(data)
}

*/